package hk.mrtomato.control;

import java.util.ArrayList;

import hk.mrtomato.dto.MrdateDTO;
import hk.mrtomato.help.ActionForward;
import hk.mrtomato.model.MrBoardService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class UpdateDateAction implements Action {

	@Override
	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) {
		
		ActionForward forward = new ActionForward();
		String seq = request.getParameter("seq");
		String title = request.getParameter("title");
		String content = request.getParameter("content");
		MrdateDTO dto = new MrdateDTO();
		dto.setSeq(Integer.parseInt(seq));
		dto.setTitle(title);
		dto.setContent(content);
		
		MrBoardService service = MrBoardService.getInstance();
		boolean isC = service.updateDate(dto);
		if(isC) {
			MrdateDTO after = service.detailDate(seq);
			String year = after.getMrdate().substring(0, 4);
			String month = after.getMrdate().substring(5,7);
			String day = after.getMrdate().substring(8, 10);
			
			String date = year+"/"+month+"/"+day;
			ArrayList<MrdateDTO> datelist = service.dayCheckGetDate(date);
			request.setAttribute("datelist", datelist);
			forward.setUrl("datelist");
		}
		
		return forward;
	}

}
